import axios from 'axios';
import router from '@/router';


// 添加响应拦截器
axios.interceptors.response.use(function (response) {
	// 对响应数据做点什么
	if(response.data.status == "failure"){
		router.push({path:'/Refresh'});
	}else{
		return response;
	}
}, function (error) {
	// 对响应错误做点什么
	return Promise.reject(error);
});

// 初始化产品详情
export function initProductDetail(productId){
    return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/detail/info',
		params: {
			productId: productId
		},
		responseType: 'json',
		// headers: {'X-Requested-With': 'aaaaaaa'}
	});
}

// 初始化首页
export function initHome(){
    return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/home/data',
		responseType: 'json'
	});
}
// 初始化产品列表页
export function initNewsListPage(productType){
    return axios({
		method: 'get',
		// 0-投顾服务  1-资讯 2-工具
		// url: '/api/wx/advisershop/v2/home/products?productType=1',
		url: '/api/wx/advisershop/v2/home/products',
		params: {
			productType: productType
		},
		responseType: 'json'
	});
}

// 获取风险等级
export function getRisk(productId){
    return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/risk/check',
		params: {
			productId: productId
		},
		responseType: 'json'
	});
}

// 风险揭示书
export function getRiskAnnounce(productId){
    return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/risk/riskPage',
		params: {
			productId: productId
		},
		responseType: 'json'
	});
}

// 产品协议
export function getProductDeal(productId){
    return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/risk/protocol',
		params: {
			productId: productId
		},
		responseType: 'json'
	});
}

// 确认订单
export function initAffirmOrder(productId){
    return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/order/index',
		params: {
			productId: productId
		},
		responseType: 'json'
	});
}

// 获取推荐人名字
export function getAdvirseName(tel){
	return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/recommend/info?mobile='+tel,
		responseType: 'json'
	});
}

// 初始化选择
export function initSelect(productId){
	return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/adviser/branchName',
		params: {
			productId: productId
		},
		responseType: 'json'
	});
}

// 通过branchCode获取团队
export function getTeam(branchCode){
	return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/adviser/teamCode',
		params: {
			branchCode: branchCode
		},
		responseType: 'json'
	});
}

// 选择页面获取成员
export function getSelectMember(productId,branchCode,teamId){
	return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/adviser/advisers',
		params: {
			productId: productId,
			branchCode: branchCode,
			teamId: teamId
		},
		responseType: 'json'
	});
}

// 初始化选择部门页面
export function initDep(){
	return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/adviser/allBranchs',
		responseType: 'json'
	});
}


// 搜索部门
export function searchDep(txt){
	return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/adviser/branchs',
		params: {
			keyWord: txt
		},
		responseType: 'json'
	});
}


// 确认订单提交数据
export function holdData(_data){
	return axios({
		method: 'post',
		url: '/api/wx/advisershop/v2/order/confirm',
		data: _data,
		responseType: 'json'
	});
}


// 初始化我的订单
export function initMyOrder(status,pageSize,currentPage,crmAuth){
    return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/myorder/orderList',
		params: {
			status: status,
			pageSize: pageSize,
			currentPage: currentPage
		},
		responseType: 'json',
		headers: {
			'crmAuth': crmAuth
		}
	});
}

// 订单详情
export function initOrderDetail(orderId,crmAuth){
	return axios({
		method: 'get',
		url: '/api/wx/advisershop/v2/myorder/orderDetail',
		params: {
			orderId: orderId
		},
		responseType: 'json',
		headers: {
			'crmAuth': crmAuth
		}
	});
}

// 保存修改的手机及邮箱
export function saveInfo(mobile ,email ,crmAuth){
	return axios({
		method: 'post',
		url: '/api/wx/advisershop/v2/receiveInfo',
		params: {
			mobile: mobile,
			email: email
		},
		responseType: 'json',
		headers: {
			'crmAuth': crmAuth
		}
	});
}